package app.msy.cn.rxandroid.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;

import app.msy.cn.rxandroid.MainActivity;
import app.msy.cn.rxandroid.R;
import app.msy.cn.rxandroid.presenter.LoginPresenterImpl;
import app.msy.cn.rxandroid.ui.view.ILoginView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class LoginActivity extends AppCompatActivity implements ILoginView {

    @BindView(R.id.login_progress)
    ProgressBar loginProgress;
    @BindView(R.id.et_phone)
    AutoCompleteTextView etPhone;
    @BindView(R.id.et_pwd)
    EditText etPwd;
    @BindView(R.id.btn_login)
    Button btnLogin;
    @BindView(R.id.btn_gallery)
    Button btnGallery;

    LoginPresenterImpl loginPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        ButterKnife.bind(this);

        loginPresenter = new LoginPresenterImpl(this);
    }

    @Override
    public void showProgress() {
        loginProgress.setVisibility(View.VISIBLE);
    }

    @Override
    public void hideProgress() {
        loginProgress.setVisibility(View.GONE);
    }

    @Override
    public void clearUserName() {
        etPhone.setText("");
    }

    @Override
    public void clearPwd() {
        etPwd.setText("");
    }

    @Override
    public String getUserName() {
        return etPhone.getText().toString();
    }

    @Override
    public String getPwd() {
        return etPwd.getText().toString();
    }

    @Override
    public void goToMain() {
        startActivity(new Intent(this, MainActivity.class));
    }

    @OnClick({R.id.btn_login, R.id.btn_gallery})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_login:
                loginPresenter.login();
                break;
            case R.id.btn_gallery:
                startActivity(new Intent(this, GalleryActivity.class));
                break;
        }
    }
}
